<?php
	session_start();
	require_once('functions.php');
	
	if( $_SESSION['account_type_code'] != 1 && $_SESSION['account_type_code'] != 2) 
	{
		header("Location:index.php?response_msg=Please login.");
		exit;
	}
	
	$sailor_id = $_SESSION['sid'];
	
	$boat_id = $_REQUEST['boat_id'];
	$month = intval($_REQUEST['month']);
	$day = intval($_REQUEST['day']);
	$year = intval($_REQUEST['year']);
	
	
	if(!$boat_id )
	{	
		$error_msg = "Please fill in all the required values.";
	}
	
	if(!checkdate($month, $day, $year) )
	{	
		$error_msg = "Invalid date.";
	}
	
	if($error_msg)
	{
		header("Location:reservations.php?response_msg=".$error_msg);
		exit;
	}
	else
	{
		
		$date = $year."-".$month."-".$day;
		$new_reservation = add_new_reservation($sailor_id, $boat_id, $date);
		if( $new_reservation )
		{
			header("Location:reservations.php?response_msg=New reservation added.");
			exit;
		}
		else
		{
			header("Location:reservations.php?response_msg=An error has occurred. New reservation could not be made.".$_SESSION['response_msg']);
			exit;
		}
	}
?>